package com.ryskoo.catering.productimage.repository;

import com.ryskoo.catering.productimage.domain.ProductImagePO;
import com.ryskoo.framework.core.repository.BasicJPAImpl;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ProductImageJPAImpl extends BasicJPAImpl<ProductImagePO> implements IProductImageRepository{
    @Override
    public void deleteByMainUuid(String mainUuid) {
        String hql = "delete from ProductImagePO o where o.productUuid = :productUuid";
        Query query = getH4Session().createQuery(hql);
        query.setString("productUuid",mainUuid);
        query.executeUpdate();
    }

    @Override
    public void deleteByMainUuids(List<String> mainUuids) {
        String hql = "delete from ProductImagePO o where o.productUuid in (:productUuids)";
        Query query = getH4Session().createQuery(hql);
        query.setParameterList("productUuids",mainUuids);
        query.executeUpdate();
    }

    @Override
    public List<ProductImagePO> getImagesByMainUuid(String mainUuid) {
        String hql = "from ProductImagePO o where o.productUuid = :productUuid";
        Query query = getH4Session().createQuery(hql);
        query.setString("productUuid",mainUuid);

        return query.list();
    }
}
